import jwt from "jsonwebtoken";
export const getUserFromReq = async (req)=>{
    const token = req.cookies['token']
    if(token){
        const payload = jwt.verify(token, process.env.JWT_SECRET)
        if(payload.account){
            return {
                account:payload.account,
                nickname:payload.nickname
            }
        }else{
            return null
        }
    }else{
        return null
    }
}
//判断是不是移动端
export const getUserFromIsMobile = (req)=>{
    const userAgent = req.headers['user-agent'] || '';
    const isMobile = /iPhone|iPad|iPod|Android/i.test(userAgent);
    return isMobile;
}